package cn.yotta.user.web.autoconfiguration.properties;

import com.google.common.collect.Lists;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.List;

/**
 * @author wyaoyao
 * @date 2022/11/8 17:14
 */
@ConfigurationProperties(prefix ="yotta.user.login")
@Data
public class WhitePathsProperties {

    /**
     * 免登录白名单
     */
    public List<String> whitePaths = Lists.newArrayList();

    public void add(String...  targetPaths) {
        if (targetPaths != null) {
            for (String path : targetPaths) {
                if (StringUtils.isNotEmpty(path)) {
                    whitePaths.add(format(path));
                }
            }
        }
    }

    private String format(String path) {
        // 如果不是/ 开头，帮忙追加
        if (!path.startsWith("/")){
            return "/" + path;
        }
        return path;
    }
}
